home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / Amiga_Mail_Vol2 / Archives / Plain / so92 / SIGF_SINGLE / SIGF_Single.txt < prev    next >
Encoding:
Text File  |  1992-10-02  |  2.9 KB  |  64 lines

  1. (c)  Copyright 1992 Commodore-Amiga, Inc.   All rights reserved. The
  2. information contained herein is subject to change without notice, and
  3. is provided "as is" without warranty of any kind, either expressed or
  4. implied.  The entire risk as to the use of this information is
  5. assumed by the user.
  6.  
  7. Signalling with SIGF_SINGLE
  8.  
  9.  
  10. by John Orr
  11.  
  12.  
  13. The ROM Kernel Reference Manuals state that sixteen of a task's 32
  14. signal bits are reserved for the operating system's private use, but,
  15. like any good rule, there is an exception.  One of these sixteen
  16. bits, the SIGF_SINGLE bit, can be useful to some applications, if
  17. used correctly.
  18.  
  19. Many system functions need to put their task to sleep while waiting
  20. for a single event, which requires using one of the task's signals.
  21. Rather than forcing each of these system functions to allocate a
  22. signal, then Wait(), then deallocate the signal, the operating system
  23. has permanently allocated one signal, the SIGF_SINGLE, for this type
  24. of signalling.  When a system function needs stop a task to Wait()
  25. for a single signal, it can use SIGF_SINGLE.
  26.  
  27. The only purpose a program can use SIGF_SINGLE for is Wait()ing
  28. because the task cannot call any system functions while it is using
  29. SIGF_SINGLE.  A program that calls system functions while using
  30. SIGF_SINGLE can cause itself and the operating system serious
  31. problems because the system functions can use SIGF_SINGLE as well.
  32. If a program calls a system function while using SIGF_SINGLE, two bad
  33. things can happen:
  34.  
  35. 1) The errant task's event takes place before the system function
  36. waits on SIGF_SINGLE (or while the system function is waiting on
  37. SIGF_SINGLE).  In this case, the system function will think its event
  38. has taken place because its signal became set.  The errant task will
  39. never find out that its event has taken place, as the system function
  40. will clear the SIGF_SINGLE bit after Wait()ing on it.
  41.  
  42. 2) The errant task's event and the system function's event take place
  43. while the system function is waiting on SIGF_SINGLE.  In this case,
  44. the system function will function normally, clear the SIGF_SINGLE
  45. bit, and exit.  The errant task will never know that its event has
  46. taken place.
  47.  
  48. Before Wait()ing on SIGF_SINGLE, clear it using SetSignal():
  49.  
  50.     SetSignal(0L, SIGF_SINGLE);
  51.  
  52. This step is necessary because it is possible that the last system
  53. function that used the SIGF_SINGLE signal did not clear the
  54. SIGF_SINGLE bit.
  55.  
  56. Also, an application should not wait on other signals while it is
  57. waiting on SIGF_SINGLE.  Waiting on other signals at the same time
  58. makes it possible for a program to wake up while the SIGF_SINGLE is
  59. still outstanding.  If this happens, the program will still have to
  60. go back to sleep, which requires calling a system function.
  61.  
  62. SIGF_Single.c is a simple example of using the SIGF_SINGLE signal.
  63. It starts a child process and waits for that child process to signal
  64. the main process using the SIGF_SINGLE signal.